#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: Use the charts api to make me a radar plot of scores -- Deprecated due to API changes
#Usage: radar_plot.pl output_prefix inputfile

use List::Util qw(max);

my %base_headers;
my @headers = split(/\t/, <>);
#This is going to need to be fixed to account for missing values
my @values = split(/\t/, <>);
shift @headers;
shift @values;
my $chartsize = 200;
for(my $i=0;$i<=$#headers;$i++) {
	chomp $headers[$i];
	my @parts = split(/_/, $headers[$i]);
	$base_headers{$parts[0]}++;
	my $val = 0;
	if ($values[$i] == 0) {
		$val = 5;
	} else {
		my @parts = split(/e+/, sprintf("%e",$values[$i]));
		$val = -1*$parts[-1] - ($parts[0]/10);
	}
	$val = int($val/5 * 100);
	if ($val < 0) { $val = 0; }
	#Add a little bit of buffer so that plots are more understandable
	$val += 5;
	print STDERR join("\t", $headers[$i], $val, sprintf("%e",$values[$i]), $values[$i]) . "\n";
	if ($parts[1] =~ /weighted/) {
		push(@weighted, $val);
	} else {
		push(@unweighted, $val);
	}
}

my $url = "http://chart.googleapis.com/chart?cht=r&chs=$chartsize&chds=a&chf=bg,s,65432100&chd=t:" . join("|", join(",", @weighted, $weighted[0]), join(",", @unweighted, $unweighted[0])) . "&chm=B,C6D9FD,0,1.0,5.0|B,FF990080,1,1.0,5.0&chls=2.0,4.0,0.0|2.0,4.0,0.0&chxt=x&chxl=0:|" . join("|",keys(%base_headers)) . "&chxr=0,0.0,360.0";
print `wget '$url' -O -`;
